/** @file bar.cpp
* @brief  Bar
* @date  2010/10/20
*/
#include "frgui.h"
#include "widget.h"
#include "bar.h"

#include "message.h"
#include "gdi.h"

Bar::Bar(HWND parent):Widget(parent)
{
    name="Bar";
    activable =0;
    
    style =TWIND_HBAR;
}

Bar::~Bar()
{
}

void Bar::draw(Rect *r)
{
    if(! lifeState) return;
    pDC->fillRect(rect.x0, rect.y0, rect.x1,rect.y1, 0x00);
    pDC->drawRect(rect.x0, rect.y0, rect.x1, rect.y1, 0x0f);
    
    switch(style)
    {
    case TWIND_HBAR:
        pDC->fillRect(rect.x0,rect.y0, rect.x0+(rect.x1-rect.x0)*position/(highPosition-lowPosition), rect.y1, 0x0F);
        break;
    case TWIND_VBAR:
    case TWIND_RHBAR:
    case TWIND_RVBAR:
        break;
    }

    pDC->dirty(max(r->x0,rect.x0), max(r->y0,rect.y0), min(r->x1,rect.x1), min(r->y1,rect.y1));
    Widget::draw(r);
}

void Bar::setValue(int value)
{
   if(value>= lowPosition && value <=highPosition) 
   {
       position =value;
       draw(&rect);
    }
}

int Bar::eventHandler(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam)
{
    return Widget::eventHandler(hWnd, iMsg, wParam, lParam);
}


